package com.zzyl.serve.controller.member;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.serve.domain.member.Reservation;
import com.zzyl.serve.dto.member.ReservationDto;
import com.zzyl.serve.service.member.IReservationService;
import com.zzyl.serve.vo.member.ReservationCountBytimeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;



import java.util.List;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags =  "预约信息相关接口")
public class MemberReservationController extends BaseController
{
    @Autowired
    private IReservationService reservationService;
    // TODO 查询当前人的取消预约次数
    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        Integer cancelledReservationCount = reservationService.getCancelledReservationCount();
        return R.ok(cancelledReservationCount);

    }
    // TODO 查询每个时间段剩余预约次数,满了就不能去预约,
    @GetMapping("/countByTime")

    public R getCountByTime(Long time) {
        List<ReservationCountBytimeVo> countByTime = reservationService.getCountByTime(time);
        return R.ok(countByTime);

    }

    // TODO 新增预约,参数有5个我们把它们封装到ReservationDto
    @PostMapping
    public AjaxResult insertReservation(@RequestBody ReservationDto reservationDto) {
        System.out.println(reservationDto);


        return toAjax(reservationService.insertReservation(reservationDto));



    }
    //TODO 分页查询预约,返回结果套了2层
    @GetMapping("/page")
    public R<TableDataInfo> list(Reservation reservation) {
        startPage();
        List<Reservation> list = reservationService.selectReservationList(reservation);
        return R.ok(getDataTable(list));
    }
    // TODO 取消预约
    @PutMapping("/{id}/cancel")
    public R cancelReservation(@PathVariable Long id) {
        int i = reservationService.cancelReservation(id);
        return  R.ok();

    }

}